package com.meshnetics.gb.type.impl.zcl;

import java.util.Arrays;
import java.util.GregorianCalendar;

/**
 * @author Pavlov Dmitry dpavlov@meshnetics.com
 */
public class Time extends FixedBytesDataValue {
    private static final long TIME_IN_MILLIS = new GregorianCalendar(2000, 0, 0, 0, 0, 0).getTimeInMillis();


    public Time(FixedBytesDataType type, byte[] value) {
        super(type, value);
    }


    protected boolean isUnsigned() {
        return true;
    }


    public Object toObject() {
        long time = ((Number) super.toObject()).longValue();
        return new Long(time + TIME_IN_MILLIS);
    }

    public boolean isInvalid() {
        return Arrays.equals(value, new byte[]{(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff});
    }
}
